package utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Calendar;
import java.util.Locale;

public class utils {
	
	public static final String[] TESTER_ID = {"smc-dq-1", "smc-dq-2", "smc-dq-3","smc-dq-4", 
		"smc-dq-5", "smc-dq-6", "smc-dq-7", "smc-dq-8", "smc-dq-9", "smc-dq-10", "smc-dq-11", 
		"smc-dq-12", "smc-dq-13", "smc-dq-14", "smc-dq-15", "smc-dq-16", "smc-dq-17",
		"smc-dq-18", "smc-dq-19", "smc-dq-20", "smc-dq-21", "smc-dq-22", "smc-dq-23", "smc-dq-24",
		"smc-dq-25", "smc-dq-26", "smc-dq-27", "smc-dq-28", "smc-dq-29", "smc-dq-30", "smc-dq-31",
		"smc-dq-32", "smc-dq-33", "smc-dq-34", "smc-dq-35", "smc-dq-36", "smc-dq-37", "smc-dq-38",
		"smc-dq-39", "smc-dq-40"};
	
	public static final String[] TESTER_PASSWORD = {"smc1", "smc2", "smc3","smc4", 
		"smc5", "smc6", "smc7", "smc8", "smc9", "smc10", "smc11", 
		"smc12", "smc13", "smc14", "smc15", "smc16", "smc17",
		"smc18", "smc19", "smc20", "smc21", "smc22", "smc23", "smc24",
		"smc25", "smc26", "smc27", "smc28", "smc29", "smc30", "smc31",
		"smc32", "smc33", "smc34", "smc35", "smc36", "smc37", "smc38",
		"smc39", "smc40"};
	

	public static String md5(String source) 
	{
		String MD5 = "";

		try {

			MessageDigest md = MessageDigest.getInstance("MD5");

			md.update(source.getBytes());

			byte byteData[] = md.digest();

			StringBuffer sb = new StringBuffer();

			for (int i = 0; i < byteData.length; i++) {
				sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
			}

			MD5 = sb.toString();

		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();

		}

		return MD5;
	}
	
/*	private int byte2int(byte[] b)
	{
		 int intV =  (b[0] << 24) + ((b[1] & 0xFF) << 16) + ((b[2] & 0xFF) << 8) + (b[3] & 0xFF);
		 
		 return intV;
	}*/
	
	public static byte[] md5(byte[] source)
	{
		byte[] md5 = new byte[]{0x00};
		
		try
		{
			MessageDigest md = MessageDigest.getInstance("MD5");
			
			md.update(source);
			
			md5 = md.digest();
			
		} catch (NoSuchAlgorithmException e)
		{
			e.printStackTrace();
		}
		
		return md5;
	}
	
	public static DateContext getToday()
	{
		Calendar calendar = Calendar.getInstance(Locale.KOREA);
		
		DateContext dateContext = new DateContext();
		
		dateContext.year = calendar.get(Calendar.YEAR);
		dateContext.month = calendar.get(Calendar.MONTH) + 1;
		dateContext.dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
		dateContext.hourOfDay = calendar.get(Calendar.HOUR_OF_DAY);
		dateContext.minute = calendar.get(Calendar.MINUTE);
		dateContext.second = calendar.get(Calendar.SECOND);
		
		return dateContext;
	}
	
	public static class DateContext
	{
		public int	year = 0;
		public int	month = 0;
		public int	dayOfMonth = 0;
		public int	hourOfDay = 0;
		public int	minute = 0;
		public int	second = 0;
	}
	
}
